<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div style="width: 100%; height: 100%">
    <div class="bg">
      <div class="text1">
        <b>双线质量管控体</b>
      </div>
      <div class="text2">
        <b>力求每件产品 、每个细节都尽善尽美</b>
      </div>
      <div class="text3">
        <b
          >够专业
          <div style="margin-top: 28px"></div>
          才放心</b
        >
      </div>
      <div class="text7">
        <b>ORDER聚造</b>
      </div>
      <div class="text8">
        <b>ORDER聚造</b>
      </div>
      <div class="box1">
        <div class="touminBox1"></div>
        <div class="touminBox2"></div>
      </div>
      <div class="box2">
        <div class="text4">
          All Rights Reserved &copy; 2021 版权所有 &nbsp; &nbsp; &nbsp; ｜ &nbsp; 粤ICP备18069755号
        </div>
      </div>
      <div class="box3">
        <div class="loginBox">
          <div class="text5">欢迎使用</div>
          <div class="text6"><b>系统登陆</b></div>
          <el-form
            ref="loginForm"
            :model="state.ruleForm"
            :rules="state.rules"
            label-width="100px"
            @keydown.enter="submitForm"
            class="demo-ruleForm"
          >
            <div class="inputDiv">
              <el-form-item prop="userName">
                <el-input
                  size="large"
                  v-model="state.ruleForm.userName"
                  placeholder="账号"
                ></el-input>
              </el-form-item>
            </div>
            <div class="inputDiv">
              <el-form-item prop="passWord">
                <el-input
                  size="large"
                  v-model="state.ruleForm.passWord"
                  placeholder="密码"
                ></el-input>
              </el-form-item>
            </div>
            <!-- <el-form-item>
              <el-button class="submit" size="large" @click.stop="submitForm" color="#6C52EA" long
                >{{ activeTab === 2 ? '登录 / 注册' : '登录' }}
              </el-button>
            </el-form-item> -->
          </el-form>
          <div class="submit" @click="submitForm">登录</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref, reactive } from 'vue'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'
import { getUserInfos } from '@/apis/login/login'

import { getCurrentInstance } from 'vue'
import md5 from 'js-md5' //导入
const { proxy } = getCurrentInstance() as any
proxy.$md5 = md5 //md5转换为vue原型
const state = reactive({
  ruleForm: {
    userName: '',
    passWord: ''
  },
  rules: {
    userName: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
    passWord: [{ required: true, message: '请输入密码', trigger: 'blur' }]
  }
})
/**
 * @desc: 登录
 */
const router = useRouter()
const loginForm = ref()
const submitForm = () => {
  loginForm.value.validate((valid: boolean) => {
    if (valid) {
      getUserInfos(state.ruleForm.userName, proxy.$md5(state.ruleForm.passWord)).then(
        (res: any) => {
          if (!res.errorMsg) {
            localStorage.setItem('token', res.token)
            localStorage.setItem('user', JSON.stringify(res))
            router.push('/home/home-page')
            // const userInfo = res.data
            // if (+userInfo.is_update_pwd === 0) {
            //   ElMessage({ type: 'error', message: '密码不符合规则，将跳转修改密码页面' })
            //   setTimeout(() => {
            //     router.push({
            //       name: 'PersonalCenter',
            //       query: {
            //         unBackFlag: true
            //       }
            //     })
            //   }, 3000)
            // } else {
            //   router.push({ name: 'HomePage' })
            // }
          } else {
            ElMessage.success('用户或密码错误！')
          }
        }
      )
    }
  })
}
</script>

<style scoped>
.bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-width: 1000px;
  zoom: 1;
  background-color: #fff;
  background: url(https://openim-1309784708.cos.ap-shanghai.myqcloud.com/182f9342163fb4222df7c76d717b8eff.png)
    no-repeat;
  background-size: cover;
  -webkit-background-size: cover;
  -o-background-size: cover;
  background-position: center 0;
  display: flex;
  overflow: none;
}
.box1 {
  width: 33%;
  height: 100%;
  z-index: 10;
}
.box2 {
  width: 397px;
  height: 100%;
  z-index: 10;
}
.box3 {
  width: 37%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}
.touminBox1 {
  margin-top: 198px;
  margin-left: 83px;
  width: 115px;
  height: 158px;
  background: #e1f2f9;
  opacity: 0.3;
}
.touminBox2 {
  margin-bottom: 235px;
  margin-left: 154px;
  width: 132px;
  height: 161px;
  background: #e1f2f9;
  opacity: 0.3;
}
.text1 {
  position: absolute;
  margin-top: 208px;
  margin-left: 130px;
  width: 22px;
  line-height: 18px;
  font-size: 16px;
  font-family: MicrosoftYaHeiUI-Bold-, MicrosoftYaHeiUI-Bold;
  font-weight: normal;
  color: #fefefe;
  writing-mode: lr-tb;
}
.text2 {
  position: absolute;
  margin-top: 208px;
  margin-left: 168px;
  width: 20px;
  line-height: 14px;
  font-size: 16px;
  font-family: MicrosoftYaHeiUI-Bold-, MicrosoftYaHeiUI-Bold;
  font-weight: normal;
  color: #ffffff;
  writing-mode: tb-rl;
}
.text3 {
  position: absolute;
  margin-top: 255px;
  margin-left: 220px;
  width: 34px;
  line-height: 28px;
  font-size: 27px;
  font-family: MicrosoftYaHeiUI-Bold-, MicrosoftYaHeiUI-Bold;
  font-weight: normal;
  color: #6bb9da;
  writing-mode: lr-tb;
}
.text4 {
  margin-top: 575px;
  width: 397px;
  height: 200px;
  font-size: 13px;
  font-family: MicrosoftYaHeiUI-Bold-, MicrosoftYaHeiUI-Bold;
  font-weight: normal;
  color: #565656;
  white-space: nowrap;
}
.loginBox {
  position: relative;
  width: 351px;
  height: 351px;
  background: #efeff0;
  border-radius: 20px;
  opacity: 0.9;
  z-index: 20;
}
.text5 {
  margin-top: 22px;
  margin-left: 31px;
  width: 51px;
  height: 16px;
  font-size: 13px;
  font-family: MicrosoftYaHeiUI-, MicrosoftYaHeiUI;
  font-weight: normal;
  color: #96a3b0;
  white-space: nowrap;
}
.text6 {
  margin-top: 6px;
  margin-left: 31px;
  width: 325px;
  height: 53px;
  font-size: 26px;
  font-family: MicrosoftYaHeiUI-Bold-, MicrosoftYaHeiUI-Bold;
  font-weight: normal;
  color: #4e4e4e;
}
.formText {
  margin-left: 29px;
  width: 37px;
  height: 16px;
  font-size: 13px;
  font-family: MicrosoftYaHeiUI-, MicrosoftYaHeiUI;
  font-weight: normal;
  color: #737474;
}
.inputDiv {
  margin-right: 20px;
}
.inputIcon {
  margin-left: 10px;
  width: 12px;
  height: 14px;
}

/* .user {
  width: 12px;
  height: 14px;
  position: absolute;
  left: 25%;
  bottom: 59%;
  background-image: url(../assets/userName.png);
  background-repeat: no-repeat;
  background-size: cover;
}
.psd {
  width: 12px;
  height: 14px;
  position: absolute;
  left: 25%;
  bottom: 42%;
  background-image: url(../assets/password.png);
  background-repeat: no-repeat;
  background-size: cover;
} */
.submit {
  display: flex;
  justify-content: center;
  align-items: center;
  color: #f4f4f5;
  font-size: 16px;
  margin-top: 52px;
  margin-left: 30px;
  width: 295px;
  height: 37px;
  background: #409eff;
  border-radius: 19px;
  opacity: 1;
  border: #409eff;
}
.text7 {
  top: 88%;
  left: 82%;
  position: absolute;
  width: 196px;
  height: 45px;
  font-size: 35px;
  font-family: MicrosoftYaHeiUI-Bold-, MicrosoftYaHeiUI-Bold;
  font-weight: normal;
  color: #d7e8fa;
  opacity: 0.3;
}
.text8 {
  top: 92%;
  left: 82%;
  position: absolute;
  width: 110px;
  height: 24px;
  font-size: 20px;
  font-family: MicrosoftYaHeiUI-Bold-, MicrosoftYaHeiUI-Bold;
  font-weight: normal;
  color: #409eff;
  white-space: nowrap;
}
</style>
